package com.heima.zuoye.day12.timu1;

public class Ticket extends Thread {
    private static int sum = 100;
    private static Object o = new Object();

    @Override
    public void run() {
        r1();
        /*while (true) {
            synchronized (o) {
                if (sum <= 0) {
                    break;
                } else {
                    sum --;
                    System.out.println(getName() + "窗口在卖票，剩余" + sum);
                }
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }*/
    }
    public synchronized void r1(){
        while (true) {
            synchronized (o) {
                if (sum <= 0) {
                    break;
                } else {
                    sum --;
                    System.out.println(getName() + "窗口在卖票，剩余" + sum);
                }
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
